/**
 * VYPe11 Project
 * VYPe11 language compiler.
 * Authors: Jozef Lang (xlangj01), 
 * 			Zoltan Zemko (xzemko01)
 * 2011
 */
package cz.vutbr.fit.VYPe.team18.VYPe11.nodes.statement;

import java.io.IOException;

import cz.vutbr.fit.VYPe.team18.VYPe11.nodes.expression.ExpressionNode;

public class ReturnStatementNode extends StatementNode {
	private ExpressionNode expression;
	
	public ReturnStatementNode(ExpressionNode expr) {
		this.expression=expr;
	}
	
	public ReturnStatementNode() {
		this.expression=null;
	}
	
	public ExpressionNode getExpression() {
		return expression;
	}

	@Override
	public void generateTAC() throws IOException {
		if(expression!=null)
		{
			expression.generateTAC();
			int i=tacCounter.getTermIndex()-1;
			this.writeTAC("Return", "_t"+i, "", "");
		}
		else
		{
			this.writeTAC("Return", "", "", "");
		}
	}
}
